package com.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.pojo.CheckItem;
import com.health.service.CheckItemService;
import com.health.vo.PageResult;
import com.health.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * checkItem表
 */
@RestController
@RequestMapping("/checkItem")
public class CheckItemController {

    @Reference//注册到dubbo容器中
    private CheckItemService checkItemService;

    /**
     * 查询检查项
     */
    @GetMapping("/findByQuery")
    public Result findByQuery(String query){
        List<CheckItem> checkItemList=checkItemService.findByQuery(query);

        //返回封装结果
        return new Result(true,"查询检查项成功",checkItemList);
    }

    /**
     * 编辑修改检查项
     */
    @PostMapping("/update")
    public Result update(@RequestBody CheckItem checkItem){
        int count=checkItemService.update(checkItem);
        if (count>0){
            return new Result(true,"编辑检查项成功");
        }

        return new Result(false,"编辑检查项失败");
    }
    /**
     * 根据id查询检查项
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        CheckItem checkItem=checkItemService.findById(id);

        return new Result(true,"根据id查询检查项成功",checkItem);
    }

    /**
     * 新增检查项
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        int count=checkItemService.add(checkItem);

        if (count>0){
            return new Result(true,"新增检查项成功");
        }

        return new Result(false,"新增检查项失败");
    }

    /**
     * 删除检查项
     */
    @DeleteMapping("/deleteById/{id}")
    public  Result deleteById(@PathVariable Integer id){
        int count=checkItemService.deleteById(id);

        if (count>0){
            return new Result(true,"删除检查项成功");
        }

        return new Result(false,"删除检查项失败");
    }

    /**
     * 检查项分页查询
     */
    @GetMapping("/findPage/{pageNow}/{pageSize}")
    public Result findPage(@PathVariable Integer pageNow,@PathVariable Integer pageSize,String query){
        PageResult<CheckItem> pageResult=checkItemService.findPage(pageNow,pageSize,query);

        return new Result(true,"检查项分页查询success",pageResult);
    }

    /**
     *查询所有检查项
     */
    @GetMapping("/findAll")
    public Result findAll(){

        List<CheckItem> checkItemList=checkItemService.findAll();

        //返回封装结果
        return new Result(true,"查询所有检查项成功",checkItemList);
    }


}
